package com.itguigu.wechat.controller;

import cn.hutool.socket.protocol.MsgDecoder;
import com.itguigu.common.result.Result;
import com.itguigu.model.wechat.Menu;
import com.itguigu.wechat.service.WechatMenuService;
import com.itguigu.wechat.service.impl.WechatMenuServiceImpl;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 菜单(wechat_menu)表控制层
 *
 * @author xxxxx
 */
@RestController
@Slf4j
@RequestMapping("/admin/wechat/menu")
public class WechatMenuController {
    /**
     * 服务对象
     */
    @Resource
    private WechatMenuService wechatMenuService;


    @ApiOperation("获取全部菜单")
    @GetMapping("findMenuInfo")
    public Result findMenoInfo() {
        return Result.success(wechatMenuService.findMenuInfo());
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(@RequestBody Menu menu) {
        log.info("新增菜单 : {}" , menu);
        boolean save = wechatMenuService.save(menu);
        return Result.success();
    }

    @ApiOperation("删除操作")
    @GetMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        log.info("要删除的菜单id : {}" , id);
        boolean remove = wechatMenuService.removeById(id);
        return Result.success();
    }

    @ApiOperation("修改操作")
    @PostMapping("update")
    public Result updateById(@RequestBody Menu menu) {
        log.info("要修改的菜单 : {}" , menu);
        boolean b = wechatMenuService.updateById(menu);
        return Result.success();
    }

    @ApiOperation(value = "获取")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        Menu menu = wechatMenuService.getById(id);
        return Result.success(menu);
    }

    @ApiOperation("同步菜单功能")
    @GetMapping("syncMenu")
    public Result createMenu() {
        log.info("推送同步菜单功能");
        wechatMenuService.syncMenu();
        return Result.success();
    }


    @ApiOperation("删除菜单功能")
    @DeleteMapping("removeMenu")
    public Result removeMenu() {
        log.info("删除菜单功能");
        wechatMenuService.removeMenu();
        return Result.success();
    }
}
